package com.lin.manager.controller.file;

import com.lin.manager.aop.Log;
import com.lin.manager.common.enums.LogEnum;
import com.lin.manager.common.resp.R;
import com.lin.manager.file.model.vo.FileVo;
import com.lin.manager.file.service.FileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

/**
 * @作者: 林江
 * @创建时间: 2024/3/21
 * @功能:
 */
@Api(tags = "文件管理")
@RestController
@RequestMapping("file")
public class FileController {

    @Autowired
    private FileService fileService;

    @ApiOperation("文件管理 - 文件上传")
    @Log(module = "文件管理", descipt = "文件上传", type = LogEnum.FILE)
    @PostMapping("upload")
    public R upload(MultipartFile file) throws Exception {
        return R.ok(fileService.upload(file));
    }

    @ApiOperation("文件管理 - 文件下载")
    @Log(module = "文件管理", descipt = "文件下载", type = LogEnum.FILE)
    @PostMapping("download/{code}")
    public void download(HttpServletResponse response,
                         @PathVariable("code") String code,
                         FileVo vo) throws Exception {
        fileService.download(vo, code, response);
    }
}